package com.catsic.pub.controllers;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.catsic.base.controller.BaseController;
import com.catsic.pub.condition.FtpCondition;
import com.catsic.pub.entity.Ftp;
import com.catsic.pub.ftp.service.FtpService;
@Controller
@RequestMapping("/ftp")
public class FtpController extends BaseController {
	@Autowired
	private FtpService ftpService;

	/**
	 * create:创建
	 * @author sgl
	 * @param ftp
	 * @return
	 */
	@RequestMapping(value = "/create" , method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> create(Ftp ftp){
		ftpService.add(ftp);
		Map<String, Object> result = new HashMap<String, Object>();
		result.put(RESULT, RESULT_SUCCESS);
		return result ;
	}
	/**
	 * update:修改
	 * @author sgl
	 * @return
	 */
	@RequestMapping(value = "/update" , method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> update(Ftp ftp){
		ftpService.update(ftp);
		Map<String, Object> result = new HashMap<String, Object>();
		result.put(RESULT, RESULT_SUCCESS);
		return result ;
	}
	
	/**
	 * delete:删除
	 * @author sgl
	 * @param id
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Map<String, Object> delete(String id){
		ftpService.delete(id);
		Map<String, Object> result = new HashMap<String, Object>();
		result.put(RESULT, RESULT_SUCCESS);
		return result;
	}
	 /**
     * 查询
	 * @author sgl
	 * @return
	 */
	@RequestMapping(value = "/query")
	@ResponseBody
	public Map<String,Object> query(FtpCondition condition,Pageable  pageable){
		Map<String,Object> map = new HashMap<String, Object>();
		Page<Ftp> page= ftpService.findAll(condition,pageable);
        map.put(CONTENT, page);
        map.put(RESULT, RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * 
	 * queryFtpByOrganCode:通过机构编码获取ftp
	 * @author zw
	 * @param organCode
	 * @return
	 */
	@RequestMapping(value = "/findByOrganCode")
	@ResponseBody
	public Map<String,Object> findFtpByOrganCode(String organCode){
		 Map<String,Object> map = new HashMap<String, Object>();
		 map.put(CONTENT, ftpService.findByOrganCode(organCode));
	     map.put(RESULT, RESULT_SUCCESS);
	     return map;
	}
	
	/**
	 * 
	 * test:测试是否能够连接成功
	 * @author zw
	 * @param organCode
	 * @return
	 */
	@RequestMapping(value = "/test")
	@ResponseBody
	public Map<String,Object> test(String id){
		 Map<String,Object> map = new HashMap<String, Object>();
		 ftpService.test(id);
	     map.put(RESULT, RESULT_SUCCESS);
	     return map;
	}
}
